#ifndef __COMMON_H_
#define __COMMON_H_

#include <inttypes.h>

// point structure for history
typedef struct pt_s {
	double 			t;
	uint16_t		y;
} pt_t;

// in-memory buffer structure for history
typedef struct buf_s {
	int 			npt;
	pt_t 			*pt;
} buf_t;

// structure for on-disk file with history
typedef struct file_s {
	char 			*name;
	pt_t			beg_pt;
	pt_t			end_pt;
	
	struct file_s 	*prev;
	struct file_s 	*next;
} file_t;

// structure for enumerated on-disk files with history
typedef struct filedb_s {
	char 			*base_dir;
	char 			*base_name;

	struct file_s 	*first;
	struct file_s 	*last;	
} filedb_t;

// config structure for history
typedef struct cfg_s {
	char			*point_name;

	buf_t 			*old;
	buf_t 			*new;
	int 			buf_size;

	filedb_t 		*filedb;
} cfg_t;

// buffer with interpolated data
typedef struct query_buf_s {
	pt_t			*values;
	int				nvalues;
	double			t_beg;
	double			t_end;
	char			*name;	
} query_buf_t;

// histories
typedef struct histories_s {
	cfg_t			*cfg;
	int				ncfg;
	
	char			*base_dir;
	int				buf_size;	
} histories_t;


#endif // __COMMON_H_